import Vue from 'vue'
import { USER_INFO, ENHANCE_PRE } from "@/store/mutation-types"
import {FOLD_TYPE, FILE_MODEL} from "@/global/globalConst";
import {ROOT_PATH} from "../global/globalConst";

const getters = {
  device: state => state.app.device,
  theme: state => state.app.theme,
  color: state => state.app.color,
  token: state => state.user.token,
  avatar: state => {state.user.avatar = Vue.ls.get(USER_INFO).avatar; return state.user.avatar},
  username: state => state.user.info.username,
  nickname: state => {state.user.info.realname = Vue.ls.get(USER_INFO).realname; return state.user.info.realname},
  welcome: state => state.user.welcome,
  permissionList: state => state.user.permissionList,
  userInfo: state => {state.user.info = Vue.ls.get(USER_INFO); return state.user.info},
  addRouters: state => state.permission.addRouters,
  onlAuthFields: state => {return state.online.authFields },
  enhanceJs:(state) => (code) => {
    state.enhance.enhanceJs[code] = Vue.ls.get(ENHANCE_PRE+code);
    return state.enhance.enhanceJs[code]
  },
  sysSafeMode: state => state.user.sysSafeMode,
  // 文件路径，key:id, value:{id, pid, parent}
  getFilePath: (state) => (pid) => {
    let path = '/'
    if (pid==='null'){
      pid=ROOT_PATH;
    }
    let id = pid
    while (id) {
      path = '/' + state.fileList.pathTreeMap[id].name + path
      id = state.fileList.pathTreeMap[id].pid
    }
    return path
  },
  // 传入目录id
  getPathTree: (state) => (pid) => {
    if (pid==='null'){
      pid=ROOT_PATH;
    }
    let list = []
    let id = pid
    while (id) {
      list.push(state.fileList.pathTreeMap[id])
      id = state.fileList.pathTreeMap[id].pid
    }
    return list.reverse();
  },

  //  操作列是否展开，false不展开，true展开
  operaColumnExpand: (state) =>
    state.fileList.operaColumnExpand !== null
      ? Number(state.fileList.operaColumnExpand)
      : document.body.clientWidth > 1280 ? FOLD_TYPE.UNFOLD : FOLD_TYPE.FOLD,
  selectedColumnList: (state) =>
    state.fileList.selectedColumnList === null
      ? ["extension", "fileSize", "updateTime", "deleteTime"]
      : state.fileList.selectedColumnList.split(","), //  列显隐
  currentFileModel: (state) => state.fileList.fileModel === null ? FILE_MODEL.TABLE : Number(state.fileList.fileModel), //  文件展示模式，0列表模式，1网格模式 2 时间线模式

}


export default getters
